import datetime
import os

# from langchain.agents import create_react_agent
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.tools import tool
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent

base_url = os.environ.get("DASHSCOPE_BASE_URL")
model_name = os.environ.get("DASHSCOPE_MODEL_NAME")
os.environ["OPENAI_API_KEY"] = os.getenv("DASHSCOPE_API_KEY")
# base_url = os.environ.get("BAOCLOUD_DS_BASE_URL")
# model_name = os.environ.get("BAOCLOUD_DS_MODEL_NAME")
# os.environ["OPENAI_API_KEY"] = os.getenv("BAOCLOUD_DS_API_KEY")
# os.environ["TAVILY_API_KEY"] = "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"

llm = ChatOpenAI(base_url=base_url, model_name=model_name)

template = "你是一个友好的智能AI助手，请回答问题：{question}"
prompt_template = ChatPromptTemplate.from_template(template)


@tool
def get_current_date():
    """获取今天日期，返回今天是几月几号"""
    print("call get_current_date")
    return datetime.datetime.today().strftime("%Y-%m-%d")


# print(get_current_date())
agent = create_react_agent(
    model=llm,
    tools=[get_current_date],
    # tools=[],
    prompt="请在必要时使用tools中的方法"
)

res = agent.invoke({"messages": [{"role": "user", "content": "今天是几月几号？"}]})
print(res)
